;; JAL: modified versions of stuff in ido-model that can't be tweaked via
;; configuration variables.

(defun ido-completion-help ()
  "Show possible completions in a *File Completions* buffer."
  (interactive)
  (setq ido-rescan nil)
  (let ((temp-buf (get-buffer ido-completion-buffer))
	display-it full-list)
    (if (and (eq last-command this-command) temp-buf)
	;; scroll buffer
	(let (win (buf (current-buffer)))
	  (display-buffer temp-buf nil nil)
	  (set-buffer temp-buf)
	  (setq win (get-buffer-window temp-buf))
	  (if (pos-visible-in-window-p (point-max) win)
	      (if (or ido-completion-buffer-all-completions
		      (boundp 'ido-completion-buffer-full))
		  (set-window-start win (point-min))
		(with-no-warnings
		  (set (make-local-variable 'ido-completion-buffer-full) t))
		(setq full-list t
		      display-it t))
	    (scroll-other-window))
	  (set-buffer buf))
      (setq display-it t))
    (if display-it
	(with-output-to-temp-buffer ido-completion-buffer
	  (let ((completion-list (sort
				  (cond
				   (ido-directory-too-big
				    (message "Reading directory...")
				    (setq ido-directory-too-big nil
					  ido-ignored-list nil
					  ido-cur-list (ido-all-completions)
					  ido-rescan t)
				    (ido-set-matches)
				    (or ido-matches ido-cur-list))
				   (ido-use-merged-list
				    (ido-flatten-merged-list (or ido-matches ido-cur-list)))
                                   ;; JAL: I don't like the fact that if you hit TAB twice in a
                                   ;; row, the second (and subsequent) completion lists show all
                                   ;; files in the current directory, rather than just the ones
                                   ;; that match what you've typed so far. This unfortunately
                                   ;; cannot be customized because the `full-list' local variable
                                   ;; is not accessible from outside. So I'm taking it out of the
                                   ;; cond test entirely.
                                   ;;
                                   ;; Old code:
				   ;; ((or full-list ido-completion-buffer-all-completions)
				   ;;  (ido-all-completions))
				   ((or ido-completion-buffer-all-completions)
				    (ido-all-completions))
                                   ;; JAL: End of customizations.
				   (t
				    (copy-sequence (or ido-matches ido-cur-list))))
				  #'ido-file-lessp)))
	    (if (featurep 'xemacs)
		;; XEmacs extents are put on by default, doesn't seem to be
		;; any way of switching them off.
		;; This obscure code avoids a byte compiler warning in Emacs.
		(let ((f 'display-completion-list))
		  (funcall f completion-list
			   :help-string "ido "
			   :activate-callback
			   '(lambda (x y z) (message "Doesn't work yet, sorry!"))))
	      ;; else running Emacs
	      ;;(add-hook 'completion-setup-hook 'completion-setup-function)
	      (display-completion-list completion-list)))))))
